﻿using Infragistics.Win.UltraWinGrid;
using Microsoft.Office.Interop.Word;
using System;
using System.Windows.Forms;
using Titan.FIS.Enum;

namespace Titan.FIS.LMS
{
    public partial class FrmManuallyInput : Form
    {
        public LaboratoryType _LabType = LaboratoryType.RC;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="testCode"></param>
        public FrmManuallyInput(string testCode, LaboratoryType labType)
        {
            InitializeComponent();

            if (!string.IsNullOrEmpty(testCode))
            {
                tB_AsNo.Text = testCode;
            }
            tB_PatchCode.Enabled = false;

            _LabType = labType;
            comboBoxMType.SelectedIndex = 0;
            comboBoxSType.SelectedIndex = 0;
            comboBoxCType.SelectedIndex = 0;
            tB_AsNo.Text = "";
            this.ActiveControl = tB_AsNo;
            if (_LabType == LaboratoryType.Third)
            {
                tBMT.Enabled = false;
                tBMAD.Enabled = false;
                tBAAD.Enabled = false;
                tBVAD.Enabled = false;
                tBSTAD.Enabled = false;
                tBQBAD.Enabled = false;
            }
        }

        /// <summary>
        /// 插入单项指标数据到数据库
        /// </summary>
        /// <param name="strAsTestCode">化验码</param>
        /// <param name="testIndex">1032....</param>
        /// <param name="testValue">数据</param>
        /// <param name="iCType"></param>
        /// <param name="iSType"></param>
        /// <param name="iMType"></param>
        /// <returns></returns>
        private bool InsertConfirmedData(string strAsTestCode, int testIndex, string testValue, int iCType, int iSType, int iMType, bool isDelete)
        {
            if (isDelete)
            {
                //删除数据
                var msgResult = DataOperate.DataQuery.DoDeleteTestData(strAsTestCode, testIndex, testValue);
                if (msgResult == "success")
                    return true;
                MessageBox.Show(msgResult);
                return false;
            }
            bool bConfirmed = true;
            var errMsg = DataOperate.DataQuery.DoQueryLmsIndexState(strAsTestCode, iCType, iSType, iMType, testIndex, ref bConfirmed);
            if (!string.IsNullOrEmpty(errMsg))
            {
                MessageBox.Show(errMsg);
                return false;
            }
            if (bConfirmed)
            {
                MessageBox.Show(string.Format(@"化验编码【{0}】已确认过化验指标【{1}】的平行样化验结果，请勿重复确认！", strAsTestCode, EnumClass.GetEnumDes((LaboratoryIndex)int.Parse(testIndex.ToString()))));
                return false;
            }
            if (!DataOperate.DataExecProc.DoInsertConfirmedData(strAsTestCode, testIndex, testValue, (int)_LabType, iMType, iCType, iSType, ref errMsg))
            {
                MessageBox.Show(errMsg);
                return false;
            }
            return true;
        }

        private void ultraButton1_Click(object sender, EventArgs e)
        {
            SaveData(true);
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            SaveData();
        }

        public void SaveData(bool isDelete = false)
        {
            string strChangeCode = "";
            if (string.IsNullOrEmpty(comboBoxMType.Text))
            {
                MessageBox.Show("请先输入化验方式！");
                return;
            }
            if (comboBoxMType.SelectedIndex == 0)
            {
                if (string.IsNullOrEmpty(tB_AsNo.Text))
                {
                    MessageBox.Show("请输入化验编码！");
                    return;
                }
            }
            else
            {
                if (string.IsNullOrEmpty(tB_PatchCode.Text))
                {
                    MessageBox.Show("请输入批次编码！");
                    return;
                }
            }

            if (string.IsNullOrEmpty(comboBoxCType.Text))
            {
                MessageBox.Show("请输入化验类型！");
                return;
            }
            if (string.IsNullOrEmpty(comboBoxSType.Text))
            {
                MessageBox.Show("请输入试样类型！");
                return;
            }

            if (!string.IsNullOrEmpty(tBSmall.Text) || !string.IsNullOrEmpty(tBMedium.Text) || !string.IsNullOrEmpty(tBLarge.Text))
            {
                if (string.IsNullOrEmpty(tBSmall.Text))
                {
                    MessageBox.Show("请输入<3mm的筛分粒度后在保存！");
                    return;
                }
                if (string.IsNullOrEmpty(tBMedium.Text))
                {
                    MessageBox.Show("请输入3~10mm的筛分粒度后在保存！");
                    return;
                }
                if (string.IsNullOrEmpty(tBLarge.Text))
                {
                    MessageBox.Show("请输入>10mm的筛分粒度后在保存！");
                    return;
                }
                float values = float.Parse(tBSmall.Text);
                float valuem = float.Parse(tBMedium.Text);
                float valuel = float.Parse(tBLarge.Text);
                float sum = values + valuem + valuel;
                if (sum != 100)
                {
                    MessageBox.Show("燃煤筛分粒度输入错误，它们的和应该为100，请检查后重新输入");
                    return;
                }
            }
            if (!string.IsNullOrEmpty(tBJTXXLarge.Text) || !string.IsNullOrEmpty(tBJTXLarge.Text) || !string.IsNullOrEmpty(tBJTLarge.Text) || !string.IsNullOrEmpty(tBJTMedium.Text))
            {
                if (string.IsNullOrEmpty(tBJTXXLarge.Text))
                {
                    MessageBox.Show("请输入>80mm的筛分粒度后在保存！");
                    return;
                }
                if (string.IsNullOrEmpty(tBJTXLarge.Text))
                {
                    MessageBox.Show("请输入80~60mm的筛分粒度后在保存！");
                    return;
                }
                if (string.IsNullOrEmpty(tBJTLarge.Text))
                {
                    MessageBox.Show("请输入60~40mm的筛分粒度后在保存！");
                    return;
                }
                if (string.IsNullOrEmpty(tBJTMedium.Text))
                {
                    MessageBox.Show("请输入40-25mm的筛分粒度后在保存！");
                    return;
                }
                if (string.IsNullOrEmpty(tBJTSmall.Text))
                {
                    MessageBox.Show("请输入＜25mm的筛分粒度后在保存！");
                    return;
                }
                float valuexxl = float.Parse(tBJTXXLarge.Text);
                float valuexl = float.Parse(tBJTXLarge.Text);
                float valuel = float.Parse(tBJTLarge.Text);
                float valuem = float.Parse(tBJTMedium.Text);
                float values = float.Parse(tBJTSmall.Text);
                float tBJSum = values + valuem + valuel + valuexl + valuexxl;
                if (tBJSum != 100)
                {
                    MessageBox.Show("焦炭筛分粒度输入错误，它们的和应该为100，请检查后重新输入");
                    return;
                }
            }

            string strAsTestCode = tB_AsNo.Text;
            int sType = comboBoxSType.SelectedIndex;
            int cType = 0;
            switch (comboBoxCType.SelectedIndex)
            {
                case 0:
                    cType = 0;
                    break;
                case 1:
                    cType = 2;
                    break;
                case 2:
                    cType = 1;
                    break;
            }
            int mType = comboBoxMType.SelectedIndex;
            int emType = (int)LaboratoryTestMode.Hand;
            if (mType == 1)
            {
                emType = (int)LaboratoryTestMode.ThirdParty;
                strAsTestCode = tB_PatchCode.Text;
            }
            LaboratoryIndex index = LaboratoryIndex.MT;

            for (var i = 0; i < 24; i++)
            {
                switch (index)
                {
                    case LaboratoryIndex.MT:
                        if (!string.IsNullOrEmpty(tBMT.Text))
                        {
                            if (InsertConfirmedData(strAsTestCode, (int)LaboratoryIndex.MT, tBMT.Text, cType, sType, emType, isDelete))
                                strChangeCode = strChangeCode + "《MT》";
                        }
                        index = LaboratoryIndex.MAD;
                        break;
                    case LaboratoryIndex.MAD:
                        if (!string.IsNullOrEmpty(tBMAD.Text))
                        {
                            if (InsertConfirmedData(strAsTestCode, (int)LaboratoryIndex.MAD, tBMAD.Text, cType, sType, emType, isDelete))
                                strChangeCode = strChangeCode + "《MAD》";
                        }
                        index = LaboratoryIndex.AAD;
                        break;

                    case LaboratoryIndex.AAD:
                        if (!string.IsNullOrEmpty(tBAAD.Text))
                        {
                            if (InsertConfirmedData(strAsTestCode, (int)LaboratoryIndex.AAD, tBAAD.Text, cType, sType, emType, isDelete))
                                strChangeCode = strChangeCode + "《AAD》";
                        }
                        index = LaboratoryIndex.VAD;
                        break;

                    case LaboratoryIndex.VAD:
                        if (!string.IsNullOrEmpty(tBVAD.Text))
                        {
                            if (InsertConfirmedData(strAsTestCode, (int)LaboratoryIndex.VAD, tBVAD.Text, cType, sType, emType, isDelete))
                                strChangeCode = strChangeCode + "《VAD》";
                        }
                        index = LaboratoryIndex.QBAD;
                        break;

                    case LaboratoryIndex.QBAD:
                        if (!string.IsNullOrEmpty(tBQBAD.Text))
                        {
                            if (InsertConfirmedData(strAsTestCode, (int)LaboratoryIndex.QBAD, tBQBAD.Text, cType, sType, emType, isDelete))
                                strChangeCode = strChangeCode + "《QBAD》";
                        }
                        index = LaboratoryIndex.STAD;
                        break;

                    case LaboratoryIndex.STAD:
                        if (!string.IsNullOrEmpty(tBSTAD.Text))
                        {
                            if (InsertConfirmedData(strAsTestCode, (int)LaboratoryIndex.STAD, tBSTAD.Text, cType, sType, emType, isDelete))
                                strChangeCode = strChangeCode + "《STAD》";
                        }
                        index = LaboratoryIndex.G;
                        break;
                    case LaboratoryIndex.G:
                        if (!string.IsNullOrEmpty(tBG.Text))
                        {
                            if (InsertConfirmedData(strAsTestCode, (int)LaboratoryIndex.G, tBG.Text, cType, sType, emType, isDelete))
                                strChangeCode = strChangeCode + "《G》";
                        }
                        index = LaboratoryIndex.Y;
                        break;
                    case LaboratoryIndex.Y:
                        if (!string.IsNullOrEmpty(tBY.Text))
                        {
                            if (InsertConfirmedData(strAsTestCode, (int)LaboratoryIndex.Y, tBY.Text, cType, sType, emType, isDelete))
                                strChangeCode = strChangeCode + "《Y》";
                        }
                        index = LaboratoryIndex.X;
                        break;
                    case LaboratoryIndex.X:
                        if (!string.IsNullOrEmpty(tBX.Text))
                        {
                            if (InsertConfirmedData(strAsTestCode, (int)LaboratoryIndex.X, tBX.Text, cType, sType, emType, isDelete))
                                strChangeCode = strChangeCode + "《X》";
                        }
                        index = LaboratoryIndex.a;
                        break;
                    case LaboratoryIndex.a:
                        if (!string.IsNullOrEmpty(tBa.Text))
                        {
                            if (InsertConfirmedData(strAsTestCode, (int)LaboratoryIndex.a, tBa.Text, cType, sType, emType, isDelete))
                                strChangeCode = strChangeCode + "《a》";
                        }
                        index = LaboratoryIndex.b;
                        break;
                    case LaboratoryIndex.b:
                        if (!string.IsNullOrEmpty(tBb.Text))
                        {
                            if (InsertConfirmedData(strAsTestCode, (int)LaboratoryIndex.b, tBb.Text, cType, sType, emType, isDelete))
                                strChangeCode = strChangeCode + "《b》";
                        }
                        index = LaboratoryIndex.Small;
                        break;
                    case LaboratoryIndex.Small:
                        if (!string.IsNullOrEmpty(tBSmall.Text))
                        {
                            if (InsertConfirmedData(strAsTestCode, (int)LaboratoryIndex.Small, tBSmall.Text, cType, sType, emType, isDelete))
                                strChangeCode = strChangeCode + "《<3mm》";
                        }
                        index = LaboratoryIndex.Medium;
                        break;
                    case LaboratoryIndex.Medium:
                        if (!string.IsNullOrEmpty(tBMedium.Text))
                        {
                            if (InsertConfirmedData(strAsTestCode, (int)LaboratoryIndex.Medium, tBMedium.Text, cType, sType, emType, isDelete))
                                strChangeCode = strChangeCode + "《3~10mm》";
                        }
                        index = LaboratoryIndex.Large;
                        break;
                    case LaboratoryIndex.Large:
                        if (!string.IsNullOrEmpty(tBLarge.Text))
                        {
                            if (InsertConfirmedData(strAsTestCode, (int)LaboratoryIndex.Large, tBLarge.Text, cType, sType, emType, isDelete))
                                strChangeCode = strChangeCode + "《>10mm》";
                        }
                        index = LaboratoryIndex.TOD;
                        break;
                    case LaboratoryIndex.TOD:
                        if (!string.IsNullOrEmpty(tBTOD.Text))
                        {
                            if (InsertConfirmedData(strAsTestCode, (int)LaboratoryIndex.TOD, tBTOD.Text, cType, sType, emType, isDelete))
                                strChangeCode = strChangeCode + "《TOD》";
                        }
                        index = LaboratoryIndex.M40;
                        break;
                    case LaboratoryIndex.M40:
                        if (!string.IsNullOrEmpty(tBM40.Text))
                        {
                            if (InsertConfirmedData(strAsTestCode, (int)LaboratoryIndex.M40, tBM40.Text, cType, sType, emType, isDelete))
                                strChangeCode = strChangeCode + "《M40》";
                        }
                        index = LaboratoryIndex.M10;
                        break;
                    case LaboratoryIndex.M10:
                        if (!string.IsNullOrEmpty(tBM10.Text))
                        {
                            if (InsertConfirmedData(strAsTestCode, (int)LaboratoryIndex.M10, tBM10.Text, cType, sType, emType, isDelete))
                                strChangeCode = strChangeCode + "《M10》";
                        }
                        index = LaboratoryIndex.CRI;
                        break;
                    case LaboratoryIndex.CRI:
                        if (!string.IsNullOrEmpty(tBCRI.Text))
                        {
                            if (InsertConfirmedData(strAsTestCode, (int)LaboratoryIndex.CRI, tBCRI.Text, cType, sType, emType, isDelete))
                                strChangeCode = strChangeCode + "《CRI》";
                        }
                        index = LaboratoryIndex.CSR;
                        break;
                    case LaboratoryIndex.CSR:
                        if (!string.IsNullOrEmpty(tBCSR.Text))
                        {
                            if (InsertConfirmedData(strAsTestCode, (int)LaboratoryIndex.CSR, tBCSR.Text, cType, sType, emType, isDelete))
                                strChangeCode = strChangeCode + "《CSR》";
                        }
                        index = LaboratoryIndex.JTXXLarge;
                        break;
                    case LaboratoryIndex.JTXXLarge:
                        if (!string.IsNullOrEmpty(tBJTXXLarge.Text))
                        {
                            if (InsertConfirmedData(strAsTestCode, (int)LaboratoryIndex.JTXXLarge, tBJTXXLarge.Text, cType, sType, emType, isDelete))
                                strChangeCode = strChangeCode + "《>80mm》";
                        }
                        index = LaboratoryIndex.JTXLarge;
                        break;
                    case LaboratoryIndex.JTXLarge:
                        if (!string.IsNullOrEmpty(tBJTXLarge.Text))
                        {
                            if (InsertConfirmedData(strAsTestCode, (int)LaboratoryIndex.JTXLarge, tBJTXLarge.Text, cType, sType, emType, isDelete))
                                strChangeCode = strChangeCode + "《80~60mm》";
                        }
                        index = LaboratoryIndex.JTLarge;
                        break;
                    case LaboratoryIndex.JTLarge:
                        if (!string.IsNullOrEmpty(tBJTLarge.Text))
                        {
                            if (InsertConfirmedData(strAsTestCode, (int)LaboratoryIndex.JTLarge, tBJTLarge.Text, cType, sType, emType, isDelete))
                                strChangeCode = strChangeCode + "《60~40mm》";
                        }
                        index = LaboratoryIndex.JTMedium;
                        break;
                    case LaboratoryIndex.JTMedium:
                        if (!string.IsNullOrEmpty(tBJTMedium.Text))
                        {
                            if (InsertConfirmedData(strAsTestCode, (int)LaboratoryIndex.JTMedium, tBJTMedium.Text, cType, sType, emType, isDelete))
                                strChangeCode = strChangeCode + "《40~25mm》";
                        }
                        index = LaboratoryIndex.JTSmall;
                        break;
                    case LaboratoryIndex.JTSmall:
                        if (!string.IsNullOrEmpty(tBJTSmall.Text))
                        {
                            if (InsertConfirmedData(strAsTestCode, (int)LaboratoryIndex.JTSmall, tBJTSmall.Text, cType, sType, emType, isDelete))
                                strChangeCode = strChangeCode + "《＜25mm》";
                        }
                        index = LaboratoryIndex.NONE;
                        break;

                    default:
                        break;
                }
            }

            #region wuyou 新增

            float v05mm = 0;
            float tvQnetar = 0;
            if (!string.IsNullOrEmpty(txt05mm.Text.Trim()))
            {
                if (!float.TryParse(txt05mm.Text.Trim(), out v05mm))
                {
                    MessageBox.Show(@"请输入正确的<0.5MM数据");
                    txt05mm.Focus();
                    return;
                }
                if (InsertConfirmedData(strAsTestCode, 1047, txt05mm.Text, cType, sType, emType, isDelete))
                    strChangeCode = strChangeCode + "《＜0.5mm》";
            }
            if (!string.IsNullOrEmpty(txtQnetar.Text.Trim()))
            {
                if (!float.TryParse(txtQnetar.Text.Trim(), out tvQnetar))
                {
                    MessageBox.Show(@"请输入正确的Qnet,ar数据");
                    txtQnetar.Focus();
                    return;
                }
                if (InsertConfirmedData(strAsTestCode, (int)LaboratoryIndex.QNETAR_KCAL, txtQnetar.Text, cType, sType, emType, isDelete))
                    strChangeCode = strChangeCode + "《Qnet,ar》";
            }

            #endregion

            if (string.IsNullOrEmpty(strChangeCode))
                MessageBox.Show(@"未修改任何数据，谢谢！");
            else
            {
                MessageBox.Show(string.Format(@"手工录入化验编号《{0}》的{1}结果成功！", strAsTestCode, strChangeCode));
                this.Close();
            }
        }


        private void tBMT_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(tBMT.Text)) // || tBMT.Text.Substring(tBMT.Text.Length - 1, 1) == ".")
                {
                    return;
                }

                float MT = float.Parse(tBMT.Text);
                if (MT > 90)
                {
                    MessageBox.Show("Mt输入异常，请重新输入！");
                    tBMT.Text = tBMT.Text.Substring(0, tBMT.Text.Length - 1);
                    tBMT.Select(tBMT.TextLength, 0);
                    tBMT.ScrollToCaret();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Mt输入异常，请重新输入！" + ex.Message);
                tBMT.Text = "";
            }
        }

        private void tBMAD_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(tBMAD.Text)) // || tBMT.Text.Substring(tBMAD.Text.Length - 1, 1) == ".")
                {
                    return;
                }
                float MAD = float.Parse(tBMAD.Text);
                if (MAD > 90)
                {
                    MessageBox.Show("Mad输入异常，请重新输入！");
                    tBMAD.Text = tBMAD.Text.Substring(0, tBMAD.Text.Length - 1);
                    tBMAD.Select(tBMAD.TextLength, 0);
                    tBMAD.ScrollToCaret();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Mad输入异常，请重新输入！" + ex.Message);
                tBMAD.Text = "";
            }
        }

        private void tBAAD_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(tBAAD.Text)) // || tBMT.Text.Substring(tBAAD.Text.Length - 1, 1) == ".")
                {
                    return;
                }
                float AAD = float.Parse(tBAAD.Text);
                if (AAD > 90)
                {
                    MessageBox.Show("Aad输入异常，请重新输入！");
                    tBAAD.Text = tBAAD.Text.Substring(0, tBAAD.Text.Length - 1);
                    tBAAD.Select(tBAAD.TextLength, 0);
                    tBAAD.ScrollToCaret();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Aad输入异常，请重新输入！" + ex.Message);
                tBAAD.Text = "";
            }
        }

        private void tBVAD_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(tBVAD.Text)) // || tBMT.Text.Substring(tBVAD.Text.Length - 1, 1) == ".")
                {
                    return;
                }
                float VAD = float.Parse(tBVAD.Text);
                if (VAD > 90)
                {
                    MessageBox.Show("Vad输入异常，请重新输入！");
                    tBVAD.Text = tBVAD.Text.Substring(0, tBVAD.Text.Length - 1);
                    tBVAD.Select(tBVAD.TextLength, 0);
                    tBVAD.ScrollToCaret();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Vad输入异常，请重新输入！" + ex.Message);
                tBVAD.Text = "";
            }
        }

        private void tBSTAD_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(tBSTAD.Text)) // || tBMT.Text.Substring(tBVAD.Text.Length - 1, 1) == ".")
                {
                    return;
                }
                float STAD = float.Parse(tBSTAD.Text);
                if (STAD > 90)
                {
                    MessageBox.Show("St,ad输入异常，请重新输入！");
                    tBSTAD.Text = tBSTAD.Text.Substring(0, tBSTAD.Text.Length - 1);
                    tBSTAD.Select(tBSTAD.TextLength, 0);
                    tBSTAD.ScrollToCaret();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("St,ad输入异常，请重新输入！" + ex.Message);
                tBSTAD.Text = "";
            }
        }

        private void tBQBAD_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(tBQBAD.Text)) // || tBMT.Text.Substring(tBVAD.Text.Length - 1, 1) == ".")
                {
                    return;
                }
                float QBAD = float.Parse(tBQBAD.Text);
                if (QBAD > 90000 || QBAD < 1)
                {
                    MessageBox.Show("Qb,ad输入异常，请重新输入！");
                    tBQBAD.Text = tBQBAD.Text.Substring(0, tBQBAD.Text.Length - 1);
                    tBQBAD.Select(tBQBAD.TextLength, 0);
                    tBQBAD.ScrollToCaret();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Qb,ad输入异常，请重新输入！" + ex.Message);
                tBQBAD.Text = "";
            }
        }
        private void tBG_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(tBG.Text))
                {
                    return;
                }
                float G = float.Parse(tBG.Text);
                if (G > 150 || G < 0)
                {
                    MessageBox.Show("G输入异常，请重新输入！");
                    tBG.Text = tBG.Text.Substring(0, tBG.Text.Length - 1);
                    tBG.Select(tBG.TextLength, 0);
                    tBG.ScrollToCaret();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("G输入异常，请重新输入！" + ex.Message);
                tBG.Text = "";
            }
        }
        private void tBX_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(tBX.Text))
                {
                    return;
                }
                if (tBX.Text=="-")
                {
                    return;
                }
                float X = float.Parse(tBX.Text);
                if (X > 100)//|| X <= 0
                {
                    MessageBox.Show("X输入异常，请重新输入！");
                    tBX.Text = tBX.Text.Substring(0, tBX.Text.Length - 1);
                    tBX.Select(tBX.TextLength, 0);
                    tBX.ScrollToCaret();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("X输入异常，请重新输入！" + ex.Message);
                tBX.Text = "";
            }
        }
        private void tBY_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(tBY.Text))
                {
                    return;
                }
                float Y = float.Parse(tBY.Text);
                if (Y > 100 || Y < 0)
                {
                    MessageBox.Show("Y输入异常，请重新输入！");
                    tBY.Text = tBY.Text.Substring(0, tBY.Text.Length - 1);
                    tBY.Select(tBY.TextLength, 0);
                    tBY.ScrollToCaret();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Y输入异常，请重新输入！" + ex.Message);
                tBY.Text = "";
            }
        }
        private void tBa_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(tBa.Text))
                {
                    return;
                }
                float a = float.Parse(tBa.Text);
                if (a > 100 || a < 0)
                {
                    MessageBox.Show("a输入异常，请重新输入！");
                    tBa.Text = tBa.Text.Substring(0, tBa.Text.Length - 1);
                    tBa.Select(tBa.TextLength, 0);
                    tBa.ScrollToCaret();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("a输入异常，请重新输入！" + ex.Message);
                tBa.Text = "";
            }
        }
        private void tBb_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(tBb.Text) || tBb.Text == "-")
                {
                    return;
                }
                float b = float.Parse(tBb.Text);
                if (b > 300 || b < -100)
                {
                    MessageBox.Show("b输入异常，请重新输入！");
                    tBb.Text = tBb.Text.Substring(0, tBb.Text.Length - 1);
                    tBb.Select(tBb.TextLength, 0);
                    tBb.ScrollToCaret();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("b输入异常，请重新输入！" + ex.Message);
                tBb.Text = "";
            }
        }

        private void tBCRI_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(tBCRI.Text))
                {
                    return;
                }
                float CRI = float.Parse(tBCRI.Text);
                if (CRI > 100 || CRI < 0)
                {
                    MessageBox.Show("CRI输入异常，请重新输入！");
                    tBCRI.Text = tBCRI.Text.Substring(0, tBCRI.Text.Length - 1);
                    tBCRI.Select(tBCRI.TextLength, 0);
                    tBCRI.ScrollToCaret();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("CRI输入异常，请重新输入！" + ex.Message);
                tBCRI.Text = "";
            }
        }

        private void tBCSR_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(tBCSR.Text))
                {
                    return;
                }
                float value = float.Parse(tBCSR.Text);
                if (value > 100 || value < 0)
                {
                    MessageBox.Show("CSR输入异常，请重新输入！");
                    tBCSR.Text = tBCSR.Text.Substring(0, tBCSR.Text.Length - 1);
                    tBCSR.Select(tBCSR.TextLength, 0);
                    tBCSR.ScrollToCaret();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("CSR输入异常，请重新输入！" + ex.Message);
                tBCSR.Text = "";
            }
        }

        private void tBSmall_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(tBSmall.Text))
                {
                    return;
                }
                float value = float.Parse(tBSmall.Text);
                if (value > 100 || value < 0)
                {
                    MessageBox.Show("<3mm值输入异常，请重新输入！");
                    tBSmall.Text = tBSmall.Text.Substring(0, tBSmall.Text.Length - 1);
                    tBSmall.Select(tBSmall.TextLength, 0);
                    tBSmall.ScrollToCaret();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("<3mm值输入异常，请重新输入！" + ex.Message);
                tBSmall.Text = "";
            }
        }
        private void tBMedium_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(tBMedium.Text))
                {
                    return;
                }
                float value = float.Parse(tBMedium.Text);
                if (value > 100 || value < 0)
                {
                    MessageBox.Show("3~10mm值输入异常，请重新输入！");
                    tBMedium.Text = tBMedium.Text.Substring(0, tBMedium.Text.Length - 1);
                    tBMedium.Select(tBMedium.TextLength, 0);
                    tBMedium.ScrollToCaret();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("3~10mm值输入异常，请重新输入！" + ex.Message);
                tBMedium.Text = "";
            }
        }
        private void tBLarge_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(tBLarge.Text))
                {
                    return;
                }
                float value = float.Parse(tBLarge.Text);
                if (value > 100 || value < 0)
                {
                    MessageBox.Show(">10mm值输入异常，请重新输入！");
                    tBLarge.Text = tBLarge.Text.Substring(0, tBLarge.Text.Length - 1);
                    tBLarge.Select(tBLarge.TextLength, 0);
                    tBLarge.ScrollToCaret();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(">10mm值输入异常，请重新输入！" + ex.Message);
                tBLarge.Text = "";
            }
        }

        private void tBTOD_KeyUp(object sender, KeyEventArgs e)
        {
            var control = (TextBox)sender;
            var errMsg = "TOD值输入异常，请重新输入！";
            try
            {
                var strValue = control.Text;
                if (string.IsNullOrEmpty(strValue))
                {
                    return;
                }
                float value = float.Parse(strValue);
                if (value > 100 || value < 0)
                {
                    MessageBox.Show(errMsg);
                    control.Text = control.Text.Substring(0, control.Text.Length - 1);
                    control.Select(control.TextLength, 0);
                    control.ScrollToCaret();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(errMsg + ex.Message);
                control.Text = "";
            }
        }

        private void tBM40_KeyUp(object sender, KeyEventArgs e)
        {
            var control = (TextBox)sender;
            var errMsg = "M40值输入异常，请重新输入！";
            try
            {
                var strValue = control.Text;
                if (string.IsNullOrEmpty(strValue))
                {
                    return;
                }
                float value = float.Parse(strValue);
                if (value > 100 || value < 0)
                {
                    MessageBox.Show(errMsg);
                    control.Text = control.Text.Substring(0, control.Text.Length - 1);
                    control.Select(control.TextLength, 0);
                    control.ScrollToCaret();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(errMsg + ex.Message);
                control.Text = "";
            }
        }

        private void tBM10_KeyUp(object sender, KeyEventArgs e)
        {
            var control = (TextBox)sender;
            var errMsg = "M10值输入异常，请重新输入！";
            try
            {
                var strValue = control.Text;
                if (string.IsNullOrEmpty(strValue))
                {
                    return;
                }
                float value = float.Parse(strValue);
                if (value > 100 || value < 0)
                {
                    MessageBox.Show(errMsg);
                    control.Text = control.Text.Substring(0, control.Text.Length - 1);
                    control.Select(control.TextLength, 0);
                    control.ScrollToCaret();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(errMsg + ex.Message);
                control.Text = "";
            }
        }

        private void tBJTXXLarge_KeyUp(object sender, KeyEventArgs e)
        {
            var control = (TextBox)sender;
            var errMsg = ">80mm值输入异常，请重新输入！";
            try
            {
                var strValue = control.Text;
                if (string.IsNullOrEmpty(strValue))
                {
                    return;
                }
                float value = float.Parse(strValue);
                if (value > 100 || value < 0)
                {
                    MessageBox.Show(errMsg);
                    control.Text = control.Text.Substring(0, control.Text.Length - 1);
                    control.Select(control.TextLength, 0);
                    control.ScrollToCaret();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(errMsg + ex.Message);
                control.Text = "";
            }
        }

        private void tBJTXLarge_KeyUp(object sender, KeyEventArgs e)
        {
            var control = (TextBox)sender;
            var errMsg = "80~60mm值输入异常，请重新输入！";
            try
            {
                var strValue = control.Text;
                if (string.IsNullOrEmpty(strValue))
                {
                    return;
                }
                float value = float.Parse(strValue);
                if (value > 100 || value < 0)
                {
                    MessageBox.Show(errMsg);
                    control.Text = control.Text.Substring(0, control.Text.Length - 1);
                    control.Select(control.TextLength, 0);
                    control.ScrollToCaret();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(errMsg + ex.Message);
                control.Text = "";
            }
        }

        private void tBJTLarge_KeyUp(object sender, KeyEventArgs e)
        {
            var control = (TextBox)sender;
            var errMsg = "60~40mm值输入异常，请重新输入！";
            try
            {
                var strValue = control.Text;
                if (string.IsNullOrEmpty(strValue))
                {
                    return;
                }
                float value = float.Parse(strValue);
                if (value > 100 || value < 0)
                {
                    MessageBox.Show(errMsg);
                    control.Text = control.Text.Substring(0, control.Text.Length - 1);
                    control.Select(control.TextLength, 0);
                    control.ScrollToCaret();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(errMsg + ex.Message);
                control.Text = "";
            }
        }

        private void tBJTMedium_KeyUp(object sender, KeyEventArgs e)
        {
            var control = (TextBox)sender;
            var errMsg = "40~25mm值输入异常，请重新输入！";
            try
            {
                var strValue = control.Text;
                if (string.IsNullOrEmpty(strValue))
                {
                    return;
                }
                float value = float.Parse(strValue);
                if (value > 100 || value < 0)
                {
                    MessageBox.Show(errMsg);
                    control.Text = control.Text.Substring(0, control.Text.Length - 1);
                    control.Select(control.TextLength, 0);
                    control.ScrollToCaret();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(errMsg + ex.Message);
                control.Text = "";
            }
        }

        private void tBJTSmall_KeyUp(object sender, KeyEventArgs e)
        {
            var control = tBJTSmall;
            var errMsg = "＜25mm值输入异常，请重新输入！";
            try
            {
                var strValue = control.Text;
                if (string.IsNullOrEmpty(strValue))
                {
                    return;
                }
                float value = float.Parse(strValue);
                if (value > 100 || value < 0)
                {
                    MessageBox.Show(errMsg);
                    control.Text = control.Text.Substring(0, control.Text.Length - 1);
                    control.Select(control.TextLength, 0);
                    control.ScrollToCaret();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(errMsg + ex.Message);
                control.Text = "";
            }
        }

        private void comboBoxMType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBoxMType.SelectedIndex == 0)
            {
                tB_AsNo.Text = "";
                tB_AsNo.Enabled = true;
                tB_PatchCode.Text = "";
                tB_PatchCode.Enabled = false;
                comboBoxSType.Enabled = true;
                comboBoxCType.Enabled = true;
            }
            else
            {
                tB_PatchCode.Text = "";
                tB_PatchCode.Enabled = true;
                tB_AsNo.Text = "";
                tB_AsNo.Enabled = false;
                comboBoxSType.SelectedIndex = 0;
                comboBoxSType.Enabled = false;
                comboBoxCType.SelectedIndex = 0;
                comboBoxCType.Enabled = false;
            }
        }

        private void btnPaste_Click(object sender, EventArgs e)
        {
            var code = Clipboard.GetText();
            try
            {
                var tmp = int.Parse(code.ToString()); if (tmp <= 0 || code.Length != 9)
                    return;
                tB_AsNo.Text = code;
            }
            catch { }
        }

        private void txtQnetar_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(txtQnetar.Text))
                {
                    return;
                }
                float val = 0;
                if (!float.TryParse(txtQnetar.Text, out val))
                {
                    MessageBox.Show("Qnetar输入异常，请重新输入！");
                    txtQnetar.Select(txtQnetar.TextLength, 0);
                    txtQnetar.ScrollToCaret();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Qnetar输入异常，请重新输入！" + ex.Message);
                txtQnetar.Text = "";
            }
        }

        private void txt05mm_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(txt05mm.Text))
                {
                    return;
                }
                float val = 0;
                if (!float.TryParse(txt05mm.Text, out val))
                {
                    MessageBox.Show("＜0.5mm:输入异常，请重新输入！");
                    txt05mm.Select(txt05mm.TextLength, 0);
                    txt05mm.ScrollToCaret();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("＜0.5mm:输入异常，请重新输入！" + ex.Message);
                txt05mm.Text = "";
            }
        }

        private void tBX_Leave(object sender, EventArgs e)
        {

        }
    }
}
